﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Cn.Cellula.Model.System;
using Cn.Edwon.Spring;
using Cn.Cellula.Biz.Port;
using System.Reflection;

namespace Cn.Cellula.Client {
    public class CategoryUtil {
        public static Common.Logging.ILog log = Common.Logging.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
        public static String BuildCategoryPath(String ownerKey, String typeKey, String categoryKey, String urlPattern, String separate) {
            StringBuilder sb = new StringBuilder();
            try {
                IList<TSysCategoryEO> list = BizFactory.Get<ICategoryBiz>().LoadCategoryPath(ownerKey, typeKey, categoryKey);
                if (list != null && list.Count > 0) {
                    for (int i = list.Count-1; i >= 0; i--) {
                        TSysCategoryEO eo = list[i];
                        if (i < list.Count - 1)
                            sb.Append(separate);
                        if (!String.IsNullOrEmpty(urlPattern)) {
                            sb.Append(urlPattern.Replace("{0}", eo.CategoryId).Replace("{1}", eo.CategoryName));
                        } else {
                            sb.Append(eo.CategoryName);
                        }
                    }
                } else {
                    sb.Append("--");
                }
            } catch (Exception ex) {
                log.Error(ex.Message);
                sb.Append("---");
            }
            return sb.ToString();
        }
    
    }
}
